package org.jivesoftware.smackx.pubsub;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import org.jivesoftware.smackx.packet.DataForm;

public class ConfigureForm extends Form
{
  public ConfigureForm(Form paramForm)
  {
    super(paramForm.getDataFormToSend());
  }

  public ConfigureForm(DataForm paramDataForm)
  {
    super(paramDataForm);
  }

  public ConfigureForm(FormType paramFormType)
  {
    super(paramFormType.toString());
  }

  private void addField(ConfigureNodeFields paramConfigureNodeFields, String paramString)
  {
    String str = paramConfigureNodeFields.getFieldName();
    if (getField(str) == null)
    {
      FormField localFormField = new FormField(str);
      localFormField.setType(paramString);
      addField(localFormField);
    }
  }

  private String getFieldValue(ConfigureNodeFields paramConfigureNodeFields)
  {
    return ((String)getField(paramConfigureNodeFields.getFieldName()).getValues().next());
  }

  private Iterator<String> getFieldValues(ConfigureNodeFields paramConfigureNodeFields)
  {
    return getField(paramConfigureNodeFields.getFieldName()).getValues();
  }

  private List<String> getListSingle(String paramString)
  {
    ArrayList localArrayList = new ArrayList(1);
    localArrayList.add(paramString);
    return localArrayList;
  }

  private static boolean parseBoolean(String paramString)
  {
    int i;
    if ((!("1".equals(paramString))) && (!("true".equals(paramString))))
      i = 0;
    while (true)
    {
      return i;
      i = 1;
    }
  }

  public AccessModel getAccessModel()
  {
    AccessModel localAccessModel;
    String str = getFieldValue(ConfigureNodeFields.access_model);
    if (str == null)
      localAccessModel = null;
    while (true)
    {
      return localAccessModel;
      localAccessModel = AccessModel.valueOf(str);
    }
  }

  public String getBodyXSLT()
  {
    return getFieldValue(ConfigureNodeFields.body_xslt);
  }

  public Iterator<String> getChildren()
  {
    return getFieldValues(ConfigureNodeFields.children);
  }

  public ChildrenAssociationPolicy getChildrenAssociationPolicy()
  {
    ChildrenAssociationPolicy localChildrenAssociationPolicy;
    String str = getFieldValue(ConfigureNodeFields.children_association_policy);
    if (str == null)
      localChildrenAssociationPolicy = null;
    while (true)
    {
      return localChildrenAssociationPolicy;
      localChildrenAssociationPolicy = ChildrenAssociationPolicy.valueOf(str);
    }
  }

  public Iterator<String> getChildrenAssociationWhitelist()
  {
    return getFieldValues(ConfigureNodeFields.children_association_whitelist);
  }

  public int getChildrenMax()
  {
    return Integer.parseInt(getFieldValue(ConfigureNodeFields.children_max));
  }

  public String getCollection()
  {
    return getFieldValue(ConfigureNodeFields.collection);
  }

  public String getDataType()
  {
    return getFieldValue(ConfigureNodeFields.type);
  }

  public String getDataformXSLT()
  {
    return getFieldValue(ConfigureNodeFields.dataform_xslt);
  }

  public ItemReply getItemReply()
  {
    ItemReply localItemReply;
    String str = getFieldValue(ConfigureNodeFields.itemreply);
    if (str == null)
      localItemReply = null;
    while (true)
    {
      return localItemReply;
      localItemReply = ItemReply.valueOf(str);
    }
  }

  public int getMaxItems()
  {
    return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_items));
  }

  public int getMaxPayloadSize()
  {
    return Integer.parseInt(getFieldValue(ConfigureNodeFields.max_payload_size));
  }

  public NodeType getNodeType()
  {
    NodeType localNodeType;
    String str = getFieldValue(ConfigureNodeFields.node_type);
    if (str == null)
      localNodeType = null;
    while (true)
    {
      return localNodeType;
      localNodeType = NodeType.valueOf(str);
    }
  }

  public PublishModel getPublishModel()
  {
    PublishModel localPublishModel;
    String str = getFieldValue(ConfigureNodeFields.publish_model);
    if (str == null)
      localPublishModel = null;
    while (true)
    {
      return localPublishModel;
      localPublishModel = PublishModel.valueOf(str);
    }
  }

  public Iterator<String> getReplyRoom()
  {
    return getFieldValues(ConfigureNodeFields.replyroom);
  }

  public Iterator<String> getReplyTo()
  {
    return getFieldValues(ConfigureNodeFields.replyto);
  }

  public Iterator<String> getRosterGroupsAllowed()
  {
    return getFieldValues(ConfigureNodeFields.roster_groups_allowed);
  }

  public String getTitle()
  {
    return getFieldValue(ConfigureNodeFields.title);
  }

  public boolean isDeliverPayloads()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.deliver_payloads));
  }

  public boolean isNotifyConfig()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.notify_config));
  }

  public boolean isNotifyDelete()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.notify_delete));
  }

  public boolean isNotifyRetract()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.notify_retract));
  }

  public boolean isPersistItems()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.persist_items));
  }

  public boolean isPresenceBasedDelivery()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.presence_based_delivery));
  }

  public boolean isSubscibe()
  {
    return parseBoolean(getFieldValue(ConfigureNodeFields.subscribe));
  }

  public void setAccessModel(AccessModel paramAccessModel)
  {
    addField(ConfigureNodeFields.access_model, "list-single");
    setAnswer(ConfigureNodeFields.access_model.getFieldName(), getListSingle(paramAccessModel.toString()));
  }

  public void setBodyXSLT(String paramString)
  {
    addField(ConfigureNodeFields.body_xslt, "text-single");
    setAnswer(ConfigureNodeFields.body_xslt.getFieldName(), paramString);
  }

  public void setChildren(List<String> paramList)
  {
    addField(ConfigureNodeFields.children, "text-multi");
    setAnswer(ConfigureNodeFields.children.getFieldName(), paramList);
  }

  public void setChildrenAssociationPolicy(ChildrenAssociationPolicy paramChildrenAssociationPolicy)
  {
    addField(ConfigureNodeFields.children_association_policy, "list-single");
    setAnswer(ConfigureNodeFields.children_association_policy.getFieldName(), paramChildrenAssociationPolicy.toString());
  }

  public void setChildrenAssociationWhitelist(List<String> paramList)
  {
    addField(ConfigureNodeFields.children_association_whitelist, "jid-multi");
    setAnswer(ConfigureNodeFields.children_association_whitelist.getFieldName(), paramList);
  }

  public void setChildrenMax(int paramInt)
  {
    addField(ConfigureNodeFields.children_max, "text-single");
    setAnswer(ConfigureNodeFields.children_max.getFieldName(), paramInt);
  }

  public void setCollection(String paramString)
  {
    addField(ConfigureNodeFields.collection, "text-single");
    setAnswer(ConfigureNodeFields.collection.getFieldName(), paramString);
  }

  public void setDataType(String paramString)
  {
    addField(ConfigureNodeFields.type, "text-single");
    setAnswer(ConfigureNodeFields.type.getFieldName(), paramString);
  }

  public void setDataformXSLT(String paramString)
  {
    addField(ConfigureNodeFields.dataform_xslt, "text-single");
    setAnswer(ConfigureNodeFields.dataform_xslt.getFieldName(), paramString);
  }

  public void setDeliverPayloads(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.deliver_payloads, "boolean");
    setAnswer(ConfigureNodeFields.deliver_payloads.getFieldName(), paramBoolean);
  }

  public void setItemReply(ItemReply paramItemReply)
  {
    addField(ConfigureNodeFields.itemreply, "list-single");
    setAnswer(ConfigureNodeFields.itemreply.getFieldName(), getListSingle(paramItemReply.toString()));
  }

  public void setMaxItems(int paramInt)
  {
    addField(ConfigureNodeFields.max_items, "text-single");
    setAnswer(ConfigureNodeFields.max_items.getFieldName(), paramInt);
  }

  public void setMaxPayloadSize(int paramInt)
  {
    addField(ConfigureNodeFields.max_payload_size, "text-single");
    setAnswer(ConfigureNodeFields.max_payload_size.getFieldName(), paramInt);
  }

  public void setNodeType(NodeType paramNodeType)
  {
    addField(ConfigureNodeFields.node_type, "list-single");
    setAnswer(ConfigureNodeFields.node_type.getFieldName(), getListSingle(paramNodeType.toString()));
  }

  public void setNotifyConfig(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.notify_config, "boolean");
    setAnswer(ConfigureNodeFields.notify_config.getFieldName(), paramBoolean);
  }

  public void setNotifyDelete(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.notify_delete, "boolean");
    setAnswer(ConfigureNodeFields.notify_delete.getFieldName(), paramBoolean);
  }

  public void setNotifyRetract(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.notify_retract, "boolean");
    setAnswer(ConfigureNodeFields.notify_retract.getFieldName(), paramBoolean);
  }

  public void setPersistentItems(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.persist_items, "boolean");
    setAnswer(ConfigureNodeFields.persist_items.getFieldName(), paramBoolean);
  }

  public void setPresenceBasedDelivery(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.presence_based_delivery, "boolean");
    setAnswer(ConfigureNodeFields.presence_based_delivery.getFieldName(), paramBoolean);
  }

  public void setPublishModel(PublishModel paramPublishModel)
  {
    addField(ConfigureNodeFields.publish_model, "list-single");
    setAnswer(ConfigureNodeFields.publish_model.getFieldName(), getListSingle(paramPublishModel.toString()));
  }

  public void setReplyRoom(List<String> paramList)
  {
    addField(ConfigureNodeFields.replyroom, "list-multi");
    setAnswer(ConfigureNodeFields.replyroom.getFieldName(), paramList);
  }

  public void setReplyTo(List<String> paramList)
  {
    addField(ConfigureNodeFields.replyto, "list-multi");
    setAnswer(ConfigureNodeFields.replyto.getFieldName(), paramList);
  }

  public void setRosterGroupsAllowed(List<String> paramList)
  {
    addField(ConfigureNodeFields.roster_groups_allowed, "list-multi");
    setAnswer(ConfigureNodeFields.roster_groups_allowed.getFieldName(), paramList);
  }

  public void setSubscribe(boolean paramBoolean)
  {
    addField(ConfigureNodeFields.subscribe, "boolean");
    setAnswer(ConfigureNodeFields.subscribe.getFieldName(), paramBoolean);
  }

  public void setTitle(String paramString)
  {
    addField(ConfigureNodeFields.title, "text-single");
    setAnswer(ConfigureNodeFields.title.getFieldName(), paramString);
  }

  public String toString()
  {
    StringBuilder localStringBuilder1 = new StringBuilder(getClass().getName() + " Content [");
    Iterator localIterator1 = getFields();
    if (!(localIterator1.hasNext()))
    {
      localStringBuilder1.append(']');
      return localStringBuilder1.toString();
    }
    FormField localFormField = (FormField)localIterator1.next();
    localStringBuilder1.append('(');
    localStringBuilder1.append(localFormField.getVariable());
    localStringBuilder1.append(':');
    Iterator localIterator2 = localFormField.getValues();
    StringBuilder localStringBuilder2 = new StringBuilder();
    while (true)
    {
      while (!(localIterator2.hasNext()))
      {
        if (localStringBuilder2.length() == 0)
          localStringBuilder2.append("NOT SET");
        localStringBuilder1.append(localStringBuilder2);
        localStringBuilder1.append(')');
      }
      if (localStringBuilder2.length() > 0)
        localStringBuilder1.append(',');
      localStringBuilder2.append((String)localIterator2.next());
    }
  }
}